package web.userUI;

import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import ejb.contentManagement.LocationMgr;
import ejb.dto.LocationDTO;
import ejb.dto.PackageDTO;
import ejb.dto.SearchDTO;
import ejb.searchEngine.PackageSearch;


@ManagedBean
@SessionScoped
public class PackageSearchBean {
	
	public PackageSearchBean() {
		today = new Date();
	}
	
	@EJB
	private PackageSearch packageSearch;
	
	@EJB
	private LocationMgr locationMgr;
	
	private SearchDTO searchParameters;
	private List<PackageDTO> results;
	private Date today;
	
	public String searchPackage() {
		results = packageSearch.searchByParameters(searchParameters);
		return "/users/searchPackage?faces-redirect=true";
	}
	
	public void resetFields() {
		searchParameters = new SearchDTO();
	}
	
	public List<PackageDTO> getSamplePackages() {
		return packageSearch.getSamplePackages();
	}
	
	
	public List<LocationDTO> getAllLocations() {
		return locationMgr.getAllLocationsDTO();
	}
	
	public List<PackageDTO> getResults() {
		return results;
	}

	public void setResults(List<PackageDTO> list) {
		this.results = list;
	}
	

	public SearchDTO getSearchParameters() {
		if(searchParameters == null) searchParameters = new SearchDTO();
		return searchParameters;
	}

	public void setSearchParameters(SearchDTO searchParameters) {
		this.searchParameters = searchParameters;
	}

	public Date getToday() {
		return today;
	}

	public void setToday(Date today) {
		this.today = today;
	}


}
